
package util;

import com.oahc.bookreaderone.MainActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 数据中心 ：控制字体大小，主题背景等调节的记录与读取
 * 
 * @author caohao
 */
public class BookData {
    private static BookData instance;

    public static BookData getInstance() {
        if (instance == null) {
            instance = new BookData();
        }
        return instance;
    }

    SharedPreferences sp = MainActivity.getInstance().getSharedPreferences("SP",
            Context.MODE_PRIVATE);

    Editor editor = sp.edit();

    public void saveFontSize(float fontsize,int bookId) {
        // 存入数据
        editor.putFloat("fontSize"+bookId, fontsize);
        editor.commit();
    }

    public float getFontSize(int bookId) {
        // 读取数据
        return sp.getFloat("fontSize"+bookId, 28);
    }

    public void saveBookMark(int[] bookmark,int bookId) {
        // 存入数据
        editor.putInt("curPage"+bookId, bookmark[0]);
        editor.putInt("process"+bookId, bookmark[1]);
        editor.commit();
    }

    public int[] getBookMark(int bookId) {
        // 读取数据
        int[] bookmarks = new int[] {
                sp.getInt("curPage"+bookId, 0), sp.getInt("process"+bookId, 0)
        };
        return bookmarks;
    }

    public void saveTheme(int style,int bookId) {
        // 存入数据
        editor.putInt("themeStyle"+bookId, style);
        editor.commit();
    }

    public int getTheme(int bookId) {
        // 读取数据
        return sp.getInt("themeStyle"+bookId, 0);
    }

    public void saveAnimation(boolean open) {
        // 翻页动画
        editor.putBoolean("openAnimation", open);
        editor.commit();
    }

    public boolean getAnimation() {
        return sp.getBoolean("openAnimation", false);
    }
}
